<template>
  <div class="brw w-full h-full pl-0px pr-0px pt-17px">
    <ProTable
      ref="tableRef"
      :columns="columns"
      :init-param="initParam"
      :request-api="getTableList"
      :border="true"
    >
      <!-- 表格操作 -->
      <template #operation="scope">
        <div class="table-btn-list">
          <el-button type="warning" link @click="openRecordDetail(scope.row)"
            >查看</el-button
          >
        </div>
      </template>
    </ProTable>
  </div>
  <!-- 发布需求 -->
  <recordDetail ref="recordDetailRef" @updata="updata" />
</template>

<script setup>
import recordDetail from "./dialog/index";
import { useHandleData } from "@/hooks/useHandleData";
definePageMeta({
  middleware: ["authenticated"],
});
useHead({
  title: `承接记录-${appTitle}`,
});

const tableRef = ref();
// 表格初始参数
const initParam = reactive({
  pageNum: 1,
  pageSize: 10,
});
const getTableList = (params) => {
  if (params.timekey) {
    params.startCreateTime = params.timekey[0];
    params.endCreateTime = params.timekey[1];
  }
  return api.post(`/demandAcceptRecord/queryPage`, params, {
    loading: true,
  });
};

// 表格配置项
const columns = [
  {
    label: "需求编码",
    prop: "demandCode",
    align: "left",
    search: { el: "input", showLabel: true },
  },
  { label: "需求名称", prop: "demandTitle", align: "left" },
  {
    label: "承接时间",
    prop: "createTime",
    align: "left",
    search: {
      el: "date-picker",
      span: 2,
      key: "timekey",
      showLabel: true,
      props: {
        clearable: true,
        type: "datetimerange",
        valueFormat: "YYYY-MM-DD HH:mm:ss",
      },
    },
  },
  {
    label: "状态",
    prop: "demandStatus",
    align: "left",
    enum: needStatus,
    search: { el: "select", showLabel: true },
  },
  { prop: "operation", label: "操作", align: "center", fixed: "right" },
];

// 更新数据
const updata = () => {
  tableRef.value.getTableList();
};

// 编辑菜单
const addRef = ref();
const editFn = (title, row) => {
  addRef.value.show(title, row);
};

// 发布需求
const recordDetailRef = ref();
const openRecordDetail = (row) => {
  recordDetailRef.value.show(row.id);
};

// 结束需求
const endNeedFn = () => {
  useHandleData(
    (e) => {
      console.log(e);
    },
    { a: 1 },
    "结束该需求"
  );
};

const to = (row) => {
  navigateTo({ path: "need/detail", query: { id: row.id } });
};
</script>
